<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<!--<base href="http://test.youxiduo.com/iweb/shixin_6_2/" />-->
	<base href="http://resource.youxiduo.com/special/shihou/promoter/3233/" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name = "format-detection" content = "telephone=no">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport"  content="width=device-width,user-scalable=no">
<title>排名奖励翻3番最高一小时300元</title>
<meta name="keywords" content="游戏多">
<meta name="description" content="游戏多">
<link rel="stylesheet" href="static/css/base.css" />
<link rel="stylesheet" href="static/css/reset.css" />
<link rel="stylesheet" href="static/css/jquery-weui.css" />
<link rel="stylesheet" href="static/css/style.css" />
<script src="static/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="static/js/util.js" ></script>
<script type="text/javascript" src="static/js/config.js" ></script>
<script src="static/js/zepto.min.js"></script>
<script src="static/js/jquery-weui.js"></script>
<script language="JavaScript">var util;
var config;
var baseUrl;
var baseUrlWage;
$(function() {
	util = new Util();
	config = new Config();
	baseUrl = config.baseUrl;
	baseUrlWage = config.baseUrlWage;

	jQuery.support.cors = true;

	var time = 3;
	$(".share").click(function() {
		if(from_user_id == "0") {
			$(".pop").fadeIn(200);
			setTimeout('$(".pop").hide()', time * 1000);
		} else {
			var web_share = {
				"qq": {
					"url": share_url,
					"img": share_icon,
					"title": share_title,
					"subtitle": share_desc
				},
				"wx_person": {
					"url": share_url,
					"img": share_icon,
					"title": share_title,
					"subtitle": share_desc
				},
				"wx_group": {
					"url": share_url,
					"img": share_icon,
					"title": share_title,
					"subtitle": share_desc
				},
				"wb": {
					"url": share_url,
					"img": share_icon,
					"title": share_title,
					"subtitle": share_desc
				}
			};

			if(typeof(window.lion) != "undefined" && typeof(window.lion.web_share) == 'function') {
				window.lion.web_share(JSON.stringify(web_share));
			}
		}
	});

	//展开隐藏
	$(".box").each(function() {
		var btnShow = $(this).find(".btnShow");
		var btnHide = $(this).find(".btnHide");
		var rule = $(this).find(".rule");
		btnShow.bind("click", function() {
			rule.css('display', 'block');
			btnShow.css('display', 'none');
			btnHide.css('display', 'block');
		});
		btnHide.bind("click", function() {
			///rule.slideUp();
			rule.css('display', 'none');
			btnHide.css('display', 'none');
			btnShow.css('display', 'block');
		});
	});

	$("#btn_sign").click(function() {
		if("1" == signed) {
			return;
		}
		if(from_user_id == "0") {
			$("#login_error").fadeIn(200);
			setTimeout('$("#login_error").hide()', time * 1000);
		} else {
			signUp(); //报名操作
		}
	});

	//点击【立即报名】
	$('.btnBm').live("click", function() {
		signUp();
	});

});

//报名操作
function signUp() {
	$.ajax({
		url: baseUrl + "/ajax_sign_up",
		type: 'GET',
		async: false,
		dataType: "jsonp",
		jsonp: "callback", //服务端用于接收callback调用的function名的参数(请使用callback或jsonp)
		jsonpCallback: "success_jsonpCallback", //callback的function名称
		data: {
			'from_user_id': from_user_id,
			"share_conf_id": share_conf_id,
			"deviceId": deviceId
		},
		success: function(data) {
			if(0 == data.errorCode) { //报名成功
				$("#sign_up_success").fadeIn(200);
				setTimeout('$("#sign_up_success").hide()', 1500);
				setTimeout('location.href=location.href', 1500);
				//将【立即报名】替换为【个人中心】
				//$(".btnBm").hide();
				//$(".btnOver").css("display","block");
			} else { //报名失败
				$("#sign_up_error").html(data.errorDescription);
				$("#sign_up_error").fadeIn(200);
				setTimeout('$("#sign_up_error").hide()', 3000);
			}
		}
	});
}

//获取用户信息
function getUserInfo() {
	console.log('getUserInfo');
	$.ajax({
		url: baseUrl + '/UserInfoAjaxApiServlet',
		type: 'GET',
		async: false,
		dataType: "jsonp",
		jsonp: "callback", //服务端用于接收callback调用的function名的参数(请使用callback或jsonp)
		jsonpCallback: "success_jsonpCallback", //callback的function名称
		data: {
			'userId': from_user_id,
			"plantId": plan_Id,
			"activityId": share_conf_id
		},
		success: function(res) {
			console.log(res);
			if(res.errorCode == '0') {
				var data = res.result;
				var kaiboTimeStr = data.kaiboTimeStr;
				var income = data.income;
				if(typeof(data.kaiboTimeStr) == "undefined" && kaiboTimeStr.length < 1)
					kaiboTimeStr = "无";
				if(typeof(data.income) == "undefined" && income.length < 1)
					income = "0";
				var baoming = '<a href="javascript:void(0)" class="btnBm btnZj" title="立即报名"><img src="static/img/btnBm.png" /></a>';
				if("1" == signed) { //已报名
					baoming = '<a href="' + baseUrl + '/task/user_center?uid=' + from_user_id + '&plantId=' + plan_Id + '&activityId=' + share_conf_id + '" title="我的收益"><span class="btnOver btnZj" style="display:none1;" title="我的收益"><img src="static/img/btnSy.png" /></span></a>';
				}

				var html = '<div class="userInfo">' +
					'<span class="userHead"><img src="' + data.icon + '" /></span>' +
					'<span class="userName">' + data.nickName + '</span>' +
					'<span class="userTime">时长：<i>' + kaiboTimeStr + '</i></span>' +
					'<span class="userMoney">总收益：<i>' + income + '元</i></span>' +
					baoming +
					'</div>';
				$(".state").prepend(html);
			}
		},
		error: function(res) {
			console.log(JSON.stringify(res));
		}
	});

}

function success_jsonpCallback() {}

//获取用户排名
function getUserRank() {
	var url = baseUrlWage + '/UserRankAndExtra';
	var dateStr = $('#time').val().split(" ")[0];
	var data = {
		"activityId": share_conf_id,
		"userId": from_user_id,
		"startDate": dateStr,
		"endDate": dateStr
	};
	requestRemoteDate(url, data, function(res) {
		console.log(JSON.stringify(res));
		if(res.errorCode == "0") {
			var result = res.result;
			var rank = result.rank;
			var wage = result.shiya;
			var viewStatus = result.viewStatus;
			var viewTotal = result.viewTotal;

			if(parseInt(rank) > parseInt(viewTotal)) {
				rank = "0";
				wage = "0";
			}
			if(rank == "0")
				rank = "无";
			else
				rank += "名";
			if(wage == "0")
				wage = "无";
			else
				wage = (parseInt(wage) / 20) + "元"
			$('#rank').html(rank);
			$('#wage').html(wage);
			if(viewStatus == "1") {
				$('.nav').show();
			}
		}
	});
}

function requestRemoteDate(url, data, callback) {
	console.log("url --> " + url);
	console.log("data --> " + JSON.stringify(data))
	$.ajax({
		url: url,
		type: 'GET',
		dataType: "json",
		data: data,
		success: callback,
		error: function(data, t, e) {
			console.log("data --> " + JSON.stringify(data));
			console.log("data --> " + JSON.stringify(e));
			var status = data.status;
			console.log(url + "获取数据失败!");
		}
	});
}

//获取当天日期
function getNowFormatDate(year, month, day) {
	year = year || 0;
	month = month || 0;
	day = day || 0;
	var date = new Date();
	date.setFullYear(date.getFullYear() + year);
	date.setMonth(date.getMonth() + month);
	date.setDate(date.getDate() + day); //获取day天后的日期 
	var seperator1 = "-";
	var seperator2 = ":";
	var month = date.getMonth() + 1;
	var strDate = date.getDate();
	if(month >= 1 && month <= 9) {
		month = "0" + month;
	}
	if(strDate >= 0 && strDate <= 9) {
		strDate = "0" + strDate;
	}
	var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate; //+ " " + date.getHours() + seperator2 + date.getMinutes();
	return currentdate;
}</script>
</head>
<body>
    
	<div class="wrap">
    	<img src="static/img/top1.jpg" /> 
        <section>
        	<!---个人中心--->
        	 <div class="state">
                <div class="nav" style="display: none;">
                    <p class="navSj g-auto">时间:
                        <input class="weui_input" id="time" type="text" value="2017-06-27 00:00">
                        <input type="text"  value="2017-06-27" class="dispaly_value"/>
                        <span></span></p>
                    <p class="navPm">排名:<i id="rank">无</i></p>
                    <p class="navJl">奖励:<i id="wage">无</i></p>
                </div>    
            </div>
            <!---未登录ios--->
            <div class="noLogin"  style="display:none;"><img src="static/img/noLogin.png" /></div>
            <!---分享--->
            <a class="share sharebtn"><img src="static/img/share.png" /></a>
            <div class="header">
                <img src="static/img/bg1.png"/>
               <a href="http://m.shihou.tv/event_share/3236" class="btnHd"><img src="static/img/qdxq.png"/></a>
               <a href="http://m.shihou.tv/event_share/3296" class="btnTd"><img src="static/img/btn2.png"/></a>
            </div>

        	<div class="box">
            	<div class="header">
                	<img src="static/img/bg2.png"/>
                    <a href="http://m.shihou.tv/get_income_tos" class="tx"><img src="static/img/tx.png"/></a>
                </div>
            	<div class="rule"><img src="static/img/rule1.png"/></div>
                <a class="btnShow btn"><img src="static/img/btnShow.png"/></a>
                <a class="btnHide btn"><img src="static/img/btnHide.png"/></a>
            </div>
            <!--如何认证-->
            <div class="box">
                <img src="static/img/bg3.png"/>
                <a href="http://m.shihou.tv/event_share/3257" class="rzBtn"><img src="static/img/rz.png"/></a>
            </div>
            <!--推荐有礼-->
            <div class="box">
            	<div class="header">
                	<img src="static/img/bg4.png"/>
					<a class="share xj"><img src="static/img/xj.png"/></a>
                </div>
                <div class="rule"><img src="static/img/rule2.png"/></div>
                <a class="btnShow btn"><img src="static/img/btnShow2.png"/></a>
                <a class="btnHide btn"><img src="static/img/btnHide.png"/></a>
            </div>
        </section>
        <footer><img src="static/img/footer.jpg"/></footer>
    </div>    
    <!-- 登录 -->
	<div class="pop">请登录后再来参加活动吧~</div>
    
</body>
</html>

<script>$(function() {
	$('.dispaly_value').val(getNowFormatDate(0, 0, -1));
	$("#time").val(getNowFormatDate(0, 0, -1) + " 00:00");
	//日历
	$("#time").datetimePicker({
		min: "2017-06-27 00:00",
		max: "2017-12-31 23:59",
	});

	if(from_user_id == 0 || from_user_id == '0') { //未登录
		$('.noLogin').show();
	} else { //已登录
		$('.noLogin').hide();
		getUserInfo();
		getUserRank();
	}

	//选择好时间后点击【确定】按钮
	$('.close-picker').live("click", function() {
		getUserRank();
	});

	//活动详情页面添加链接
	console.log(config.activity_3236);
	$('#activity_detail').attr("href", config.activity_3236);
});</script>